package top.xizai.su;

import java.util.Random;

/**
 * @NAME: WSC
 * @DATE: 2021/12/15
 * @DESCRIBE:
 **/
public class TShortURL {
    private static final String BASE;

    static {

        var sb = new StringBuilder("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
        int size = sb.length();
        var random = new Random();
        //将BASE打乱
        for (int i = 0; i < size; i++) {
            var idx = Math.abs(random.nextInt() % size);

            if (i != idx) {
                char c = sb.charAt(i);
                sb.setCharAt(i, sb.charAt(idx));
                sb.setCharAt(idx, c);
            }
        }
        BASE = sb.toString();

        System.out.println(BASE);
    }


    public static String toBase62(long num) {
        StringBuilder result = new StringBuilder();
        do {
            int i = (int) (num % 62);
            result.append(BASE.charAt(i));
            num /= 62;
        } while (num > 0);

        return result.reverse().toString();
    }

    public static long toBase10(String str) {
        long result = 0;
        for (int i = 0; i < str.length(); i++) {
            result = result * 62 + BASE.indexOf(str.charAt(i));
        }
        return result;
    }


    public static void main(String[] args) {
//        Long id = 1203234L;
//        var su = toBase62(id);
//        var ret = toBase10(su);
//
//
//
//        System.out.println(su);
//        System.out.println(ret);
//        System.out.println(id == ret);

        String B = "𝄞"; // 这个就是那个音符字符，只不过由于当前的网页没支持这种编码，所以没显示。
        String C = "\uD834\uDD1E";// 这个就是音符字符的UTF-16编码
        System.out.println(C);
        System.out.println(B.length());
        System.out.println(B.codePointCount(0,B.length()));
    }


}
